#line 2 "problem.cpp"
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <cctype>

using namespace std;
class PillarsDivTwo
{
public:
        double maximalLength(vector <int> height, int w)
        {
        	size_t n = height.size();
        	double dp[2][n];
        	dp[0][0] = dp[1][0] = 0.0;
        	for (size_t i = 1; i < n; i++) {
        		// height is 1
        		dp[0][i] = max(sqrt(w*w + (height[i-1]-1)*(height[i-1]-1)) + dp[1][i-1],
        				w + dp[0][i-1]);

        		// height is height[i]
        		dp[1][i] = max(sqrt(w*w + (height[i-1]-height[i])*(height[i-1]-height[i])) + dp[1][i-1],
        				sqrt(w*w + (1-height[i])*(1-height[i])) + dp[0][i-1]);
        	}
        	return dp[0][n-1] > dp[1][n-1] ? dp[0][n-1] : dp[1][n-1];
        }



};



// Powered by FileEdit
// Powered by TZTester 1.01 [25-Feb-2003]
// Powered by CodeProcessor
